<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Admin\Model\AuthGroupModel;
use COM\Page;
/**
 * 后台内容控制器
 * @author huajie <banhuajie@163.com>
 */

class LeavewordController extends \Admin\Controller\AdminController {
	//状态定义
	private $status=array(1=>'留言提交',2=>'已回复',3=>'留言无效');
	function index(){
		//$model = D('Testmodel/Test');
		$model = new \Testmodel\TestModel();
		dump($model);
		//$Leaveword   =   D('Leaveword');
		//$list = $this->lists($Leaveword,null,null,null);
		$res = D('Leaveword')->getLeavewordJoinType();
		$this->assign('_page', $res['_page']);
        $this->assign('_total',$res['_total']);
		$this->assign('list',$res['list']);
		$this->assign('status',$this->status);
		$this->display();
	}
	function add(){	
		$data=D('Leavewordtype')->select();
		$this->assign('data',$data);
		$this->display();
	}
	function detail(){
		$id = I('get.id');
		$data = D('Leaveword')->find($id);
		$this->assign('data',$data);
		$this->display();
	}
	function save(){
		$data = I();
		if(isset($data['id'])){
			$data['rtime'] = time();
			$data['reply_userid'] = UID;
		}else{
			$data['ctime'] = time();
			$data['status'] = 1;
		}
		$res = D('Leaveword')->update($data);
        if(!$res){
            $this->error(D('Leaveword')->getError());
        }else{
            if($res['id']){
                $this->success('添加成功！', U('index'));
            }else{
                $this->success('更新成功！', U('index'));
            }
        }
	}
	function del(){
		$id = I('get.id');
		$res = D('Leaveword')->delete($id);
        if($res !== false){
            $this->success('删除分类成功！');
        }else{
            $this->error('删除分类失败！');
        }
    }
	public function setStatus(){
		$ids    =   I('request.ids');
        $status =   I('request.status');
		if(empty($ids) || !isset($status)){
            $this->error('请选择要操作的数据');
        }
		/*拼接参数并修改状态*/
        $map    =   array();
        if(is_array($ids)){
            $map['id'] = array('in', implode(',', $ids));
        }elseif (is_numeric($ids)){
            $map['id'] = $ids;
        }
		$data['status'] = $status;
		$res = D('Leaveword')->setStatus($map,$data);
        if(!$res){
            $this->error(D('Leaveword')->getError());
        }else{
            $this->success('更新成功！', U('index'));
        }
	}
	function ajax_data(){
		file_put_contents('D:\\test.txt', json_encode(I()));
		$this->ajaxReturn(json_encode(array(111)));
	}
	function area_demo(){
		$area = D('Area')->getArea();
		$this->assign('area_json',json_encode($area));
		//$this->assign('area_json',$data);
		$this->display();
	}
	function ajax_area(){
		$post = I();
		$area = D('Area')->getArea($post['parentid']);
		//file_put_contents('D:\\test.txt', json_encode($area));
		//$this->ajaxReturn(json_encode($area));
		echo json_encode($area);
	}
}
